'''
Author: didiplus
Date: 2024-08-29 10:24:51
LastEditTime: 2024-08-30 11:41:55
LastEditors: didiplus
Description: JS逆向爬取-吉林长春产权交易中心(集团)有限公司加密数据
FilePath: \pythonscript\JSReverse\吉林长春产权交易中心\get_ccprec_list_data.py
'''

import subprocess
from functools import partial
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import requests
import json
from fake_useragent import UserAgent
import execjs


import requests




def get_ccprec_data():
    headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive',
    'Content-Type': 'text/xml;charset=UTF-8',
    'Origin': 'https://www.ccprec.com',
    'Referer': 'https://www.ccprec.com/navCqzr/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': UserAgent().random,
    'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    }


    jscode=open("./ccprec.js",'r',encoding='utf-8').read()

    for page in range(1,2):
        data = execjs.compile(jscode).call("encrypt",page)
        response = requests.post('https://www.ccprec.com/honsanCloudAct', headers=headers, data=data).text
        print(execjs.compile(jscode).call("decryptCode",response))
        decrypt_data = json.loads(execjs.compile(jscode).call("decryptCode",response))
        print(decrypt_data['results'][0]['args'][0]['list'])

if __name__ == "__main__":
    get_ccprec_data()